//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Scene2D/Types/Types.h"

namespace Engine
{
namespace Scene2D
{

	//
	// Rotation 2D
	//

	struct Rotation2D
	{
	// types
	public:
		typedef Rotation2D		Self;


	// variables
	private:
		vec2	_sinCos;


	// methods
	public:
		Rotation2D () : _sinCos(0.0f, 1.0f) {}

		explicit
		Rotation2D (float angleRad) : _sinCos( SinCos(angleRad) ) {}

		explicit
		Rotation2D (const vec2 &sinCos) : _sinCos(sinCos) {}


		float			GetAngle ()			const	{ return ATan( GetSin(), GetCos() ); }

		float			GetSin ()			const	{ return _sinCos.x; }
		float			GetCos ()			const	{ return _sinCos.y; }

		vec2 const &	GetSinCos ()		const	{ return _sinCos; }
		

		mat2	ToMat2 ()					const	{ return mat2( GetCos(), -GetSin(),  GetSin(), GetCos() ); }
		vec2	Transform (const vec2 &p)	const	{ return ToMat2() * p; }


		Self	operator * (const Self &right) const
		{
			Self	res;
			res._sinCos[0] = this->GetSin() * right.GetCos() + this->GetCos() * right.GetSin();
			res._sinCos[1] = this->GetCos() * right.GetCos() - this->GetSin() * right.GetSin();
		}

		Self &	operator *= (const Self &right)
		{
			return ( (*this) = (*this) * right );
		}


		static Self		Identity ()					{ return Rotation2D( vec2( 0.0f, -1.0f ) ); }
	};



	//
	// Transform 2D
	//

	struct Transform2D
	{
	// types
	public:
		typedef Transform2D		Self;


	// variables
	private:
		vec2		_position;
		Rotation2D	_rotation;


	// methods
	public:
		Transform2D () {}

		explicit
		Transform2D (const vec2 &pos, float angleRad = 0.0f) : _position(pos), _rotation(angleRad) {}

		Transform2D (const vec2 &pos, const Rotation2D &rot) : _position(pos), _rotation(rot) {}


		vec2 const &		Position ()	const	{ return _position; }
		vec2 &				Position ()			{ return _position; }

		Rotation2D const &	Rotation ()	const	{ return _rotation; }
		Rotation2D &		Rotation ()			{ return _rotation; }
	};

	
}	// Scene2D
}	// Engine